#!/usr/bin/env python
# encoding: utf-8
# @author: liusir
# @file: log_utils.py
# @time: 2021/6/30 9:20 下午

import os
import logging

log_path = os.path.join( os.path.dirname( os.path.abspath(__file__) ) ,'..','logs','api_test.log' )

class LogUtils():
    def __init__(self,log_file_path = log_path):
        self.log_path = log_file_path
        self.log = logging.getLogger('P7P8_API_TEST')
        self.log.setLevel( logging.DEBUG )

        console_handler = logging.StreamHandler()  # 控制台输出的日志
        formatter = logging.Formatter("%(asctime)s %(name)s %(levelname)s %(message)s")
        console_handler.setFormatter(formatter)
        console_handler.setLevel(10)
        file_handler = logging.FileHandler(log_path, 'a', encoding='utf-8')
        file_handler.setFormatter( formatter )
        file_handler.setLevel(10)

        self.log.addHandler(console_handler)
        self.log.addHandler(file_handler)

        console_handler.close()
        file_handler.close()

    def get_logger(self):
        return self.log
logger = LogUtils().get_logger()  # 放置打印重复日志
if __name__ == '__main__':
    logger.debug('封装：debug')
    logger.info('info')
    logger.warning('封装L警告！！！')





# log = logging.getLogger('P7P8')
# log.setLevel( logging.DEBUG )
#
# # 通过 handler进行日志格式、日志级别等自定义配置
# console_handler = logging.StreamHandler()  # 控制台输出的日志
# formatter = logging.Formatter("Console:%(asctime)s %(name)s %(levelname)s %(message)s")
# console_handler.setFormatter( formatter )
# console_handler.setLevel( 20 )
#
# log_path = os.path.join( os.path.dirname( os.path.abspath(__file__) ) ,'..','logs','api_test.log' )
# file_handler = logging.FileHandler(log_path,'a',encoding='utf-8')
# formatter = logging.Formatter("File:%(asctime)s %(name)s %(levelname)s %(lineno)d %(message)s")
# file_handler.setFormatter( formatter )
# file_handler.setLevel( 10 )
#
# log.addHandler( console_handler )
# log.addHandler( file_handler )

# log.debug('debug')
# log.info('info')
# log.warning('警告！！！')
# log.error( '错误！！！' )
# log.critical('critical')

